import { IParam, EntityBase } from '@/core';
import { ISys_component } from './interface/i-sys-component';
import Sys_componentKeys from './sys-component-keys';

/**
 * 组件基类
 * 基于template/src/api/{{appEntities}}/{{appEntities}}-base.ts.hbs生成
 *
 * @export
 * @abstract
 * @class Sys_componentBase
 * @extends { EntityBase }
 * @implements { ISys_component }
 */
export abstract class Sys_componentBase
	extends EntityBase
	implements ISys_component
{
	/**
	 * 实体名称
	 *
	 * @readonly
	 * @type {string}
	 * @memberof Sys_componentBase
	 */
	get srfdename(): string {
		return 'SYS_COMPONENT';
	}

	/**
	 * 当前实体所有属性
	 *
	 * @protected
	 * @type {string[]}
	 * @memberof Sys_componentBase
	 */
	protected get keys(): string[] {
		return Sys_componentKeys;
	}

	/**
	 * Creates an instance of ConstactOppoBase.
	 * @param {*} [data]
	 * @memberof Sys_componentBase
	 */
	constructor(data?: any) {
		super();
		this.setData(data);
	}

	get srfkey(): string {
		return this.id;
	}

	set srfkey(val: string) {
		this.id = val;
	}

	/**
	 * 标识
	 **/
	id?: any;

	/**
	 * 代码名
	 **/
	code_name?: any;

	get srfmajortext(): string {
		return this.display_name;
	}

	set srfmajortext(val: string) {
		this.display_name = val;
	}
	/**
	 * 显示名
	 **/
	display_name?: any;

	/**
	 * 组件类型
	 **/
	component_type?: any;

	/**
	 * 上级组件标识
	 **/
	parent_id?: any;

	/**
	 * 路由
	 **/
	router_path?: any;

	/**
	 * 排序
	 **/
	sort?: any;

	/**
	 * 描述
	 **/
	description?: any;

	/**
	 * 下级组件
	 **/
	children?: any;

	/**
	 * 接口
	 **/
	apis?: any;

	/**
	 * 重置实体数据
	 *
	 * @param {IParam} [data={}]
	 * @memberof Sys_componentBase
	 */
	reset(data: IParam = {}): void {
		super.reset(data);
		this.id = data.id || data.srfkey;
		this.display_name = data.display_name || data.srfmajortext;
	}
}
